package com.emr.web.controller.emr;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emr.common.annotation.Log;
import com.emr.common.enums.BusinessType;
import com.emr.module.domain.Jstzs;
import com.emr.module.service.IJstzsService;
import com.emr.module.service.IPersonalService;
import com.emr.web.core.base.BaseController;
import com.emr.framework.web.page.TableDataInfo;
import com.emr.common.base.AjaxResult;

/**
 * 家属通知单 信息操作处理
 * 
 * @author emr
 * @date 2019-02-21
 */
@Controller
@RequestMapping("/module/jstzs")
public class JstzsController extends BaseController
{
    private String prefix = "module/jstzs";
	
	@Autowired
	private IJstzsService jstzsService;
	@Autowired
	private IPersonalService ipersonalService ;
	
	@RequiresPermissions("module:jstzs:view")
	@GetMapping()
	public String jstzs()
	{
	    return prefix + "/jstzs";
	}
	
	/**
	 * 查询家属通知单列表
	 */
	@RequiresPermissions("module:jstzs:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Jstzs jstzs)
	{
		startPage();
		if("".equals(jstzs.getPatientName())){
			jstzs.setPatientName(null);
		}
        List<Jstzs> list = jstzsService.selectJstzsList(jstzs);
		return getDataTable(list);
	}
	
	/**
	 * 新增家属通知单
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		mmap.put("posts",ipersonalService.selectIcdAll());
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存家属通知单
	 */
	@RequiresPermissions("module:jstzs:add")
	@Log(title = "家属通知单", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Jstzs jstzs)
	{		
		return toAjax(jstzsService.insertJstzs(jstzs));
	}

	/**
	 * 修改家属通知单
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Jstzs jstzs = jstzsService.selectJstzsById(id);
		mmap.put("posts", ipersonalService.selectUPersonalByIds(jstzs.getBingrenId()));
		mmap.put("jstzs", jstzs);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存家属通知单
	 */
	@RequiresPermissions("module:jstzs:edit")
	@Log(title = "家属通知单", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Jstzs jstzs)
	{		
		return toAjax(jstzsService.updateJstzs(jstzs));
	}
	
	/**
	 * 删除家属通知单
	 */
	@RequiresPermissions("module:jstzs:remove")
	@Log(title = "家属通知单", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(jstzsService.deleteJstzsByIds(ids));
	}
	
}
